<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    body {
        text-align: center;
        width: 600px;
        height: 1000px;
    }
    
    .div {
        border: 1px rgb(52, 20, 82) solid;
    }
    
    .fgs {
        font-size: 50px;
    }
    
    .imp {
        width: 100px;
        height: 100px;
        border-radius: 90;
        border: 4px pink solid
    }
</style>

<body>
    <div id="div" class="div" style="color: gray;" title="div">
        公共id ;class ;style ;title
        <div style="background-color: gray;">这是内部div</div>
    </div>
    <img src="../images/demo10/fangao.png" height="300px" width="400px" class="fg">

    <input type="text">
    <script>
        //js操作属性
        let div1 = document.getElementById("div")
        div1.title = "xxxx"
        div1.style.color = "green"
        div1.style.backgroundColor = "pink"

        //js操作属性
        div1.setAttribute("title", "yyyy")
        console.log(div1.getAttribute("title"))
        let fg = document.getElementsByTagName("img")[0]
        fg.src = "../images/demo10/fangao2.png"

        //js操作样式
        fg.style.border = "4px gray solid"
        fg.style.borderRadius = "30px"
            // div1.className="fgs"

        div.classList.add("fgs")
        console.log(div.classList)
        div.classList.remove("fgs")
            // div.classList.toggle("fgs")

        console.log("contains: ", div.classList.contains("div"))


        //事件
        //鼠标事件（点击）
        //监听事件
        div1.onclick = () => {
            console.log("监听ing")
            div.classList.toggle("fgs")
        }

        div1.addEventListener("click", (target) => {
            console.log("监听ing")
            console.log(event.target)
        })

        fg.addEventListener("click", () => {
            console.log("监听ing")
            fg.classList.toggle("imp")
        })

        fg.addEventListener("mouseenter", () => {
            console.log("鼠标进入了图片")
        })

        fg.addEventListener("mouseleave", () => {
            console.log("鼠标进入了图片")
        })

        fg.addEventListener("mousemove", () => {
            console.log("鼠标进入了图片")
        })

        let text = document.getElementsByTagName("input")[0]
        text.addEventListener("keydown", (event) => {
            console.log(event.key, "被按下了")
        })
        text.addEventListener("keyup", (event) => {
            console.log(event.key, "被松开了")
        })
    </script>
</body>

</html>